/**
 * 
 */
package com.zito.web.www;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.downlove.common.RequestContext;
import com.downlove.template.freemarker.FreeMarkerEngine;
import com.zito.manager.ArticleManager;
import com.zito.manager.ColumnManager;
import com.zito.manager.ContributeManager;
import com.zito.manager.VideoManager;
import com.zito.manager.WeblinkManager;

/**
 * @author YunHai-Home
 * 
 */
public class VideoView {

	private final static Logger logger = LoggerFactory.getLogger(VideoView.class);
	
	public void index(HttpServletRequest request, HttpServletResponse response) {
		FreeMarkerEngine fm = new FreeMarkerEngine(request, response);
		RequestContext rc = RequestContext.get();
		VideoManager manage = new VideoManager();
		com.zito.bean.Video video = new com.zito.bean.Video();
		com.zito.bean.Video last = new com.zito.bean.Video();
		com.zito.bean.Video next = new com.zito.bean.Video();
		
		long id = rc.param("id", -1);
		if (id < 1){
			try {
				rc.error(HttpServletResponse.SC_FORBIDDEN,
						"您请求的资源不存在，请从正确的渠道访问网站");
				return;
			} catch (IOException e) {
				logger.error("发现错误的请求参数 ID ： {}", rc.param("id"));
			}
		}
		try {
			video = video.Get(id);
			manage.UpdateView(video.getId());
			last = manage.getLastVideo(video.getId(), video.getPostdate());
			next = manage.getNextVideo(video.getId(), video.getPostdate());
		} catch (Exception e) {
			
		}
		fm.put("videoid", id);
		fm.put("video", video);
		fm.put("lastVideo", last);
		fm.put("nextVideo", next);
		fm.put("videoMgr", new VideoManager());
		fm.put("columnMgr", new ColumnManager());
		fm.put("articleMgr", new ArticleManager());
		fm.put("linkMgr", new WeblinkManager());
		fm.put("contributemgr", new ContributeManager());
		FreeMarkerEngine.action(fm, "www/VideoView.html");
	}
}
